const path = require('path')
 
const webpack = require("webpack");
const HtmlWebpackPlugin = require('html-webpack-plugin');

const resolve = dir => {
    return path.join(__dirname, dir)
}
module.exports = {
    publicPath: "./",
    lintOnSave: true,
    chainWebpack: config => {
        config.resolve.alias
            .set('@', resolve('src'))
            .set('~', resolve("public"))
            .set('_dom', resolve('src/components'))
            .set('_css', resolve('src/styles'))
            .set('_img', resolve('src/assets/img'))
    },

    // 设为false打包时不生成.map文件
    productionSourceMap: false,

    configureWebpack: {
        // resolve: {
        //     //  默认检查的后缀名
        //     extensions: ['.js', '.vue', '.json'],
        //     // 资源路径的别名，默认@为src
        //     alias: {
        //         // 'vue$': 'vue/dist/vue.esm.js',
        //         '@': resolve('src'),
        //         '~': resolve('public')
        //     }
        // },

        plugins: [
            // 打包构建分析工具
            // new BundleAnalyzerPlugin(),

            // 自动加载模块，而不必到处 import 或 require
            new webpack.ProvidePlugin({
                $: 'jquery',
                jQuery: 'jquery',
                _: 'lodash',
                Popper: ['popper.js', 'default'],
                utils: [path.join(__dirname, 'src/utils'), 'default'],
            }),

            // new HtmlWebpackPlugin({
            // inject : false,
            // templateParameters: (compilation, assets, assetTags, options) => {
            //     //assets.js = assets.js.concat(['/libs/jquery.min.js', '/libs/jquery.i18n.properties.min.js']);
            //     console.dir(assets);
            //     return {
            //       compilation,
            //       webpackConfig: compilation.options,
            //       htmlWebpackPlugin: {
            //         tags: assetTags,
            //         files: assets,
            //         options
            //       },
            //       'foo': 'bar'
            //     };
            // },
            // }),
        ],

        devtool: 'eval-source-map', // 用于debugger
        // cacheBusting: false
    },

    devServer: {
        proxy: {
            '/api': {

                target: process.env.VUE_APP_DEV_URL,
                changeOrigin: true,
                
                // pathRewrite: {
                //     // 实际请求的地址 需要去除/api的标记
                //     '^/api': ''
                // },
            }
        }

    }
}
